import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';

class ToastUtil {
  static show(String msg, {duration = 2000}) {
    showToast(msg,
        duration: Duration(milliseconds: duration), dismissOtherToast: true);
  }

  static showConfirmDialog(BuildContext context, String title, String content,
      {Function? onConfirm, Function? onCancel}) async {
    return await showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text(title),
            content: Text(content),
            actions: <Widget>[
              TextButton(
                child: const Text("取消", style: TextStyle(color: Colors.amber)),
                onPressed: () {
                  Navigator.of(context).pop();
                  if (onCancel != null) {
                    onCancel();
                  }
                },
              ),
              TextButton(
                child: const Text("确定", style: TextStyle(color: Colors.blue)),
                onPressed: () {
                  Navigator.of(context).pop();
                  if (onConfirm != null) {
                    onConfirm();
                  }
                },
              ),
            ],
          );
        });
  }

  static cancelToast() {
    dismissAllToast();
  }
}
